package com.shoe.controller;

import com.shoe.pojo.ShoeEvaluate;
import com.shoe.service.ShoeEvaluateService;
import com.shoe.service.impl.CommentService;
import com.shoe.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("eval")
public class EvaluateController {

    @Autowired
    ShoeEvaluateService shoeEvaluateService;
    @Autowired
    ResponseResult responseResult;
    @Autowired
    private CommentService commentService;


    @ResponseBody
    @RequestMapping("evall")
    public ResponseResult selectAll(int currPage, int pageSize){
        responseResult = commentService.findCommentList(currPage, pageSize);

        return  responseResult;
    }

//    @ResponseBody
    @PostMapping("addeval")
    public String addEvaluate(Long orderId , Byte evalLevel , String evalCon){
        ShoeEvaluate shoeEvaluate = new ShoeEvaluate();
        shoeEvaluate.setOrderNo(orderId);
        shoeEvaluate.setEvaluateLevel(evalLevel);
        shoeEvaluate.setEvaluateContent(evalCon);
        shoeEvaluate.setCreateTime(new Date());
        shoeEvaluate.setEvaluateDate(new Date());

        commentService.saveComment(shoeEvaluate);
        return "redirect:http://localhost:63343/qiguai/html/orderpush.html";
    }

    @ResponseBody
    @RequestMapping("delOneEval")
    public void delById(String evaluateId){
        commentService.deleteCommentById(evaluateId);
    }


    @ResponseBody
    @RequestMapping("delEvals")
    public void delMany(String ids){
        String[] arr = ids.split(",");
        int count = 0;
        for(String i : arr){
             commentService.deleteCommentById(i);
        }
    }
}
